<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>练习六：定义一个函数，传入一个数字数组，对数组中的数字进行排序</title>
  </head>

  <body>

  </body>
  <script>
    /* 
    练习六：定义一个函数，传入一个数字数组，对数组中的数字进行排序
    */
    var arraySort = function (arr) {
      var temp;
      //冒泡排序,从小到大排列
      for (let j = 0; j < arr.length - 1; j++) {
        for (let i = 0; i < arr.length - 1; i++) {
          if (arr[i] >= arr[i + 1]) {
            temp = arr[i];
            arr[i] = arr[i + 1];
            arr[i + 1] = temp;
          }
        }
      }
      return arr;
    }
    var arr = new Array(20, 5, 30, 1, 6);
    arr = arraySort(arr);
    console.log(arr); //[1,5,6,20,30]
  </script>

</html>